import axios from "axios"
import appFunc from '../func'
import {Notify} from "vant";


const appsecret = "iZrCGJXfY3GH3cAH2Gkm3nhS4JkznbHk";

export default {
  login: function () {
    let userAgent = navigator.userAgent;
    let start = userAgent.indexOf("MAGAPPX");
    let str = userAgent.substr(start, userAgent.length);
    // let token = str.substr(str.lastIndexOf("|") + 1, str.length);
    let token = '04a81f2b631894f4a404b006b1a8e3e4';
    let url = "http://m.slit.cn/mag/cloud/cloud/getUserInfo?token=" + token + "&secret=" + appsecret;
    axios.get(url).then(req => {
      let info = req.data;
      appFunc.setUserinfoCache(info.data.user_id, info.data.phone, info.data.name, info.data.head)
      // alert('马甲授权成功')
    })
  },
  pay: function (money, title, orderNumber, unionOrderNum, des = '') {
    let config = {
      money: money,
      title: title,
      des: des,
      payWay: {
        wallet: 1,
        weixin: 1,
        alipay: 1
      },
      orderNum: orderNumber,
      unionOrderNum: unionOrderNum,
      type: "打赏 充值等等"
    };
    console.log(config);
    mag.pay(
      config,
      function () {
        Notify({
          message: "支付成功",
          duration: 1000,
          background: '#1989fa'
        });
      },
      function () {
        Notify({
          message: '支付失败',
          duration: 1000,
        });
      }
    );
  }
}
